/**
 *@author：yanghx
 *@Date: 2020/2/7 19:52
 */
import React from 'react';
import {StyleSheet, Text, View} from 'react-native';
import {NavigationActions, StackActions} from 'react-navigation';

export default class WelcomePage extends React.Component {
  constructor(props) {
    super(props);
    this.state = {};
  }

  static propTypes = {};

  static navigationOptions = {
    //不显示头部
    headerShown: false,
  };

  /**
   *
   * 跳转到home页面，并删除welcome页面的路由栈
   */
  toHomePage = StackActions.reset({
    index: 0,
    actions: [
      //Login 要跳转的路由
      // NavigationActions.navigate({routeName: 'Home'}),
      NavigationActions.navigate({routeName: 'Home'}),
    ],
  });

  componentDidMount(): void {
    this.timer = setTimeout(() => {
      this.props.navigation.dispatch(this.toHomePage);
    }, 2000);
  }

  componentWillUnmount(): void {
    // 如果存在就清除掉
    this.timer && clearTimeout(this.timer);
  }

  render() {
    return (
      <View style={styles.container}>
        <Text style={styles.Welcome}>Welcome</Text>
        <Text style={styles.Welcome}>欢迎使用</Text>
      </View>
    );
  }
}

const styles = StyleSheet.create({
  container: {
    flex: 1,
    justifyContent: 'center',
    alignItems: 'center',
    backgroundColor: '#1d31ff',
  },
  Welcome: {
    fontSize: 26,
  },
});
